package com.xujicheng.algorithm.sort;

public class BubbleSort<T extends Comparable> extends BaseSort<T>{

    @Override
    public void sortAsc(Object[] objects) {
        for(int i = 0;i<objects.length;i++){
            for(int j = i+1;j<objects.length;j++){
                if(((Comparable)objects[i]).compareTo(objects[j])>0) {
                    Object temp = objects[i];
                    objects[i] = objects[j];
                    objects[j] = temp;
                }
            }
        }
    }

    @Override
    public void sortDesc(Object[] objects) {
        for(int i = 0;i<objects.length;i++){
            for(int j = i+1;j<objects.length;j++){
                if(((Comparable)objects[i]).compareTo(objects[j])<0) {
                    Object temp = objects[i];
                    objects[i] = objects[j];
                    objects[j] = temp;
                }
            }
        }
    }
}
